import { baseURL } from './config.js'

/**
 * 登录 
 */

// export const loginIn = (phone, password) => {
//   return new Promise((resolve,reject) => {
//     uni.request({
//       url: `/login/cellphone?phone=${phone}&password=${password}`,
//       method: 'POST',
//       success: res => {
//         console.log(res)
//         resolve(res)
//       }
//     })
//   })
// }

/**
* 所有榜单内容摘要
*/
export const topList = () => {
  let listId = ['3','0','2','1']
  return new Promise((resolve, reject) => {
    uni.request({
      url: `${baseURL}/toplist/detail`,
      method: 'GET',
      success: res => {
        let result = res.data.list
        result.length = 4
        for (let i = 0; i < listId.length; i++) {
          result[i].listId = listId[i]
        }
        resolve(result)
      }
    })
  })
}

/**
 * 排行榜详情
 */
export const rankList = id => {
  return new Promise((resolve,reject) => {
    uni.request({
      url: `${baseURL}/playlist/detail?id=${id}`,
      method: 'GET',
      success: res => {
        resolve(res)
      }
    })
  })
}

/**
 * 获取歌单详情
 */

export const getSongDetails = songId => {
  return new Promise((resolve,reject) => {
    uni.request({
      url: `${baseURL}/song/detail?ids=${songId}`,
      method: 'GET',
      success: res => {
        resolve(res)
      }
    })
  })
}

/**
 * 获取相似音乐
 */

export const getSimiSong = songId => {
  return new Promise((resolve,reject) => {
    uni.request({
      url: `${baseURL}/simi/song?id=${songId}`,
      method: 'GET',
      success: res => {
        resolve(res)
      }
    })
  })
}

/**
 * 获取歌曲评论
 */

export const getCommentMusic = songId => {
  return new Promise((resolve,reject) => {
    uni.request({
      url: `${baseURL}/comment/music?id=${songId}`,
      method: 'GET',
      success: res => {
        resolve(res)
      }
    })
  })
}

/**
 * 获取歌词
 */

export const getLyric = songId => {
  return new Promise((resolve,reject) => {
    uni.request({
      url: `${baseURL}/lyric?id=${songId}`,
      method: 'GET',
      success: res => {
        resolve(res)
      }
    })
  })
}

/**
 * 获取音乐 url地址
 */

export const getSongUrl = songId => {
  return new Promise((resolve,reject) => {
    uni.request({
      url: `${baseURL}/song/url?id=${songId}`,
      method: 'GET',
      success: res => {
        resolve(res)
      }
    })
  })
}

/**
 * 热门搜索
 */

export const getHotSearch = () => {
  return new Promise((resolve,reject) => {
    uni.request({
      url: `${baseURL}/search/hot/detail`,
      method: 'GET',
      success: res => {
        resolve(res)
      }
    })
  })
}

/**
 * 搜索结果
 */

export const searchKeyWord = word => {
  return new Promise((resolve, reject) => {
    uni.request({
      url: `${baseURL}/search?keywords=${word}`,
      method: 'GET',
      success: res => {
        resolve(res)
      }
    })
  })
}

/**
 * 搜索建议 
 */

export const searchSuggest = words => {
  return new Promise((resolve,reject) => {
    uni.request({
      url: `${baseURL}/search/suggest?keywords=${words}&type=mobile`,
      method: 'GET',
      success: res => {
        resolve(res)
      }
    })
  })
}
